﻿using ServerFramework.Tool.Singleton;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using tcpserver;

namespace server.Tool
{
    
    /// <summary>
    /// 检测客户端是否关闭的方法
    /// </summary>
    public class CheckServerStateTimer: Singleton<CheckServerStateTimer>
    {
      
        //数据周期
        private int IntervalSendData = 1000 * 20;
        private System.Threading.Timer tmrsendCacheData = null;


        public void ResetTimer()
        {
            StopTimer();
            tmrsendCacheData = new System.Threading.Timer(CacheDataDataCallBack, null, IntervalSendData, IntervalSendData);
        }

       

        /// <summary>
        /// 推送发送人的位置信息
        /// </summary>
        /// <param name="state"></param>
        private void CacheDataDataCallBack(object state)
        {
            try
            {
                CreateQueueData.Instance.Stop();
                tmrsendCacheData.Change(Timeout.Infinite, Timeout.Infinite);
            }
            catch(Exception e)
            {
                

                tmrsendCacheData.Dispose();
                tmrsendCacheData = new System.Threading.Timer(CacheDataDataCallBack, null, IntervalSendData, IntervalSendData);
            }
            finally
            {
                tmrsendCacheData.Change(IntervalSendData, IntervalSendData);
            }
        }

        private DateTime ybDateTime;
        private DateTime mogoDateTime;
       

        private void StopTimer()
        {
            if (tmrsendCacheData != null)
            {
                tmrsendCacheData.Dispose();

            }
        }

        ~CheckServerStateTimer() // 析构函数
        {
            StopTimer();
        }

    }


}
